package com.cdtye.itps.cms.controller.dict;

import com.cdtye.common.webcore.web.AjaxJson;
import com.cdtye.itps.cms.dao.dict.entity.SysDictionary;
import com.cdtye.itps.cms.service.dict.SysDictionaryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.cdtye.common.webcore.web.AjaxJson.success;

/**
 * 字典 前端控制器
 * @author Jchen
 * @date 2021-07-08
 */
@Api(tags="字典接口")
@RestController
@RequestMapping("/dict")
public class SysDictionaryController {

    @Autowired
    private SysDictionaryService modelService;


    @ApiOperation(value = "铁路类型下拉框")
    @GetMapping(value = "/railTypeList")
    public AjaxJson railTypeList() {
        List<Map<String, Object>> result = new ArrayList<>();
        // 读取oracle里面系统字段 铁路类别
        List<SysDictionary> sysDictionaryList = modelService.dictListByTypeCodeNormal("SYS000130");
        sysDictionaryList.forEach(n->{
            Map<String, Object> item = new HashMap<>();
            item.put("code", n.getDictionaryId());
            item.put("text", n.getItemName());
            result.add(item);
        });
        return success(result);
    }

    @ApiOperation("根据字典类型Code获取字典")
    @GetMapping("/dictListByTypeCode")
    AjaxJson findDict(String typeCode){
        return AjaxJson.success(modelService.dictListByTypeCodeNormal(typeCode));
    }


}
